<template>
  <el-container class="home-container" style="width:100%">
  <el-aside :width="isToggleCollapse? '56px':'200px'">
    <div class="toggle-button" @click="isCollapse">|||</div>
    <el-menu
      default-active="2"
      class="el-menu-vertical-demo"
      background-color="#8b4513"
      text-color="#fff"
      active-text-color="#ffd04b"
      unique-opened
      :collapse="isToggleCollapse"
      :collapse-transition="false"
      router
      :default-active="activeValue">
      <el-submenu :index="'/'+items.path" v-for="items in menuList" :key="items.id">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>{{items.authName}}</span>
        </template>
          <el-menu-item :index="'/'+subItems.path"
          v-for="subItems in items.children" :key="subItems.id"
          @click="activeChange('/'+subItems.path)"
          >
            <template slot="title">
          <i class="el-icon-location"></i>
          <span>{{subItems.authName}}</span>
        </template></el-menu-item>
      </el-submenu>
    </el-menu>
    </el-aside>
  <el-container>
    <el-header>
      <div class="title">
        <img src="../assets/logo.png" alt="111">
        <span>后台系统</span>
      </div>
      <div class="logout">
        <el-button @click="logout" type="primary">退出</el-button>
      </div>
    </el-header>
    <el-main><router-view></router-view></el-main>
  </el-container>
</el-container>
</template>
<script>
export default {
  data () {
    return {
      menuList: [],
      isToggleCollapse: false,
      activeValue: this.$route.path
    }
  },
  created () {
    this.getListMenu()
  },
  methods: {
    logout () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async getListMenu () {
      const { data } = await this.$http.get('menus')
      if (data.meta.status !== 200) return this.$message.error('获取菜单失败')
      console.log(data)
      this.menuList = data.data
    },
    isCollapse () {
      console.log(this.isToggleCollapse)
      this.isToggleCollapse = !this.isToggleCollapse
    },
    activeChange (aValue) {
      // window.sessionStorage.setItem('acValue', aValue)
    }
  }
}
</script>
<style lang='less' scoped>
.home-container{
  height: 100%;
}
.el-aside{
  background-color:saddlebrown;
  .el-menu {
    border-right:0;
  }
  .toggle-button {
    background-color:#4a5064;
    font-size:10px;
    line-height: 24px;
    color:#fff;
    text-align:center;
    letter-spacing:0.2em;
    cursor:pointer;
  }

}
.el-header{
  display:flex;
  justify-content: space-between;
  align-items: center;
  background-color: blue;
  .title{
    display: flex;
    justify-content: space-between;
    align-items: center;
    img{
      height: 50px;
      width:50px;
      }
    span{
      font-size: 25px;
      color:#fff;
      line-height:25px;
    }
  }
}

.el-main{
  background: white;

}

</style>
